package com.youpai.platform.user.web.api;

import com.youpai.platform.common.entity.resp.BaseResponse;
import com.youpai.platform.user.web.entity.dto.UserItemDTO;
import com.youpai.platform.user.web.entity.req.*;
import com.youpai.platform.user.service.service.UserService;
import com.youpai.platform.user.web.entity.resp.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Description: 用户相关controller
 * @Author:welles
 * @Date:2022/7/23
 */
@Slf4j
@RestController
@RequestMapping(value = "/user")
@Api(value = "UserController", tags = "用户相关")
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation(value = "用户注册")
    @PostMapping(value = "/register")
    public BaseResponse<UserLoginResp> userRegister(@RequestBody UserRegisterReq req, HttpServletResponse resp) {
        return BaseResponse.success(userService.userRegister(req,resp));
    }

    @ApiOperation(value = "账号密码登录")
    @PostMapping(value = "/login/pwd")
    public BaseResponse<UserLoginResp> userLogin(@RequestBody UserLoginReq req, HttpServletResponse resp) {
        return BaseResponse.success(userService.userLogin(req, resp));
    }

    @ApiOperation(value = "判断验证码是否正确")
    @PostMapping(value = "/verification-code/check")
    public BaseResponse<UserResp> checkVerificationCode(@RequestBody JudgeCodeReq req) {
        return BaseResponse.success(userService.checkVerificationCode(req));
    }

    @ApiOperation(value = "找回密码")
    @PostMapping(value = "/retrieve/pwd")
    public BaseResponse<UserResp> retrievePwd(@RequestBody FindPwdReq req) {
        return BaseResponse.success(userService.retrievePwd(req));
    }

    @ApiOperation(value = "获取验证码")
    @PostMapping(value = "/verification-code/send")
    public BaseResponse<SendVerificationCodeResp> sendVerificationCode(@RequestBody SendVerificationCodeReq req) {
        SendVerificationCodeResp sendVerificationCodeResp = userService.sendVerificationCode(req);
        return BaseResponse.success(sendVerificationCodeResp);
    }

    @ApiOperation(value = "查询用户详情")
    @PostMapping(value = "/get")
    public BaseResponse<GetUserInfoByTokenResp> getUserINfoByToken() {
        return BaseResponse.success(userService.getUserINfoByToken());
    }

    @ApiOperation(value = "搜索用户信息")
    @PostMapping(value = "/search")
    public BaseResponse<List<UserItemDTO>> searchUserByUidOrName(@RequestBody SearchUserReq req) {
        return BaseResponse.success(userService.searchUserByUidOrName(req));
    }

    @ApiOperation(value = "修改用户信息")
    @PostMapping(value = "/update")
    public BaseResponse<UpdateUserResp> updateUserInfo(@RequestBody UpdateUserReq req) {
        return BaseResponse.success(userService.updateUserInfo(req));
    }

    @ApiOperation(value = "修改用户类型")
    @PostMapping(value = "/modifyUserType")
    public BaseResponse<UserResp> updateUserType(@RequestBody UserTypeReq req) {
        return BaseResponse.success(userService.updateUserType(req));
    }
}
